InformIT
Exact Phrase
All Words
Enter search string and press enter!

Search Tips

MyInformIT - Collect Your Own Content Infobases - Premium Subscription Content AlphaBooks - Content in Progress Editors' Choice - What the Experts Read Free Library - Complete Books Online InformIT Store - Books and Software Download It - Freeware and Shareware ZD News - IT News and Views BrassRing.com Jobs - Find Your Dream Job

DPEC Online Training
Click to Recommend-IT
Top IT News from ZD Net
Shareware from Tucows
 
Cisco Knowledge SuiteLinux/Open SourceWindows NTWindows 2000Visual Basic
ConfigureITNetworkITWebITDatabaseITProgramIT
 

You are here : Home : Tutorial 2: Programming Beyond Visual Basic Using the Windows API

Tutorial 2: Programming Beyond Visual Basic
Using the Windows API

by Bob Reselman and Richard Peasley - June 12, 2000

Tutorial 2: Programming Beyond VB Using Windows API

Understanding the Windows API

 

Working with the API Viewer

 

Monitoring Mouse Movement with GetCursorPos

 

Keeping a Window Always on Top by Using SetWindowPos

 
Source  
 

Understanding the Windows API

The Windows Application Programming Interface (API) is a set of hundreds of predefined functions that are built into the dynamic link libraries (DLLs) and which make up the Windows operating system. End users cannot access these functions; however, programmers can access the code written in the DLLs through the API and use this code in their programs.

Understanding DLLs

A DLL (dynamic link library) is compiled code that can be accessed only by other programs at the programming level. You put functions and subroutines into DLLs so that you may share them among many programs running at the same time. DLLs are created in languages such as C(++) and Object Pascal (Delphi). The most often used DLLs in the API for 32-bit Windows operating systems are Kernel32.DLL, User32.DLL, and GDI32.DLL. You also can make DLLs in VB, but they are called ActiveX DLLs. For more information about making ActiveX DLLs in VB, see Chapter 26:"Making Object-Oriented Programs with Visual Basic" from the source text Practical Visual Basic 6.

You can program any type of Visual Basic project in order to access the Windows API if you use the Declare statement in the General Declarations section of a module. For example, you may access GetCursorPos, which locates the onscreen mouse pointer position. It is defined for use within Visual Basic as follows:

Declare Function GetCursorPos Lib "user32" _
   Alias "GetCursorPos" (lpPoint As POINTAPI) As Long

In this syntax:

Declare

is a keyword indicating an external procedure declaration.

Function

is the procedure type.

GetCursorPos

is the name of this particular external procedure.

Lib

is a keyword indicating the DLL in which to locate the function.

"user32"

is the The DLL (must be enclosed in quotation marks, no file extension required, and must be in the path-that is, the program must know where to find the DLL).

Alias

is a keyword that indicates a friendly name by which you can refer to the function.

"GetCursorPos"

is the friendly name.

LpPoint

is an argument variable.

As POINTAPI/As Long

is a keyword indicating argument type.

POINTAPI

is an argument type.

Long

is a function return type

As you can see, GetCursorPos resides in the DLL User32.DLL. The function takes one argument, lpPoint, which is a Windows-defined type: POINTAPI. The function returns a Long.

You do not need any tools other than VB itself in order to use the Windows API. Working with the API requires a great deal of extra knowledge, however. If you plan on doing any coding with the Windows API, you will need a copy of The Microsoft Developers Network CD-ROM, which ships with the Professional and Enterprise versions of Visual Basic and documents all the available Windows API functions. The CD-Rom is an extensive work that provides a large amount of sample code. Sadly, most of the code is in C, so you might need a good third-party Visual Basic book that deals with the Windows API.

 

Previous | Next

 

What's New in Visual Basic

Moving Components from MTS to COM+

Visual Basic and OOP: The Next Generation

Creating E-Mail Applications

Featured Author

Havoc Pennington Havoc Pennington

Havoc Pennington works for Red Hat Advanced Development Labs, where he enhances the Linux desktop development infrastructure and user experience. He is the author of several components of the GNOME GUI libraries, and is the primary architect of Gconf, a new GNOME configuration database library.

Featured Book

Sams Teach Yourself Shell Programming in 24 Hours Sams Teach Yourself Shell Programming in 24 Hours

Take control of your systems by harnessing the power of the shell.

 
 
 

About InformIT

|

Press Area

|

Advertising

|

Careers

Contact Us

|

Copyright, Terms & Conditions

|

Privacy Policy

 

© Copyright 2000 InformIT. All rights reserved.